// pages/goods/components/goods-filter/index.js
Component({
  properties: {
    showModal: {
      type: Boolean,
      value: false
    },
    minPrice: {
      type: Number,
      value: null
    },
    maxPrice: {
      type: Number,
      value: null
    }
  },

  data: {
    dismiss: false,
    localMinPrice: null,
    localMaxPrice: null
  },

  observers: {
    'minPrice, maxPrice': function(minPrice, maxPrice) {
      this.setData({
        localMinPrice: minPrice,
        localMaxPrice: maxPrice
      });
    }
  },

  methods: {
    onMinPriceChange(event) {
      this.setData({
        localMinPrice: event.detail.value
      });
    },

    onMaxPriceChange(event) {
      this.setData({
        localMaxPrice: event.detail.value
      });
    },

    onReset() {
      this.setData({
        localMinPrice: null,
        localMaxPrice: null
      });
      this.triggerEvent('reset');
    },

    onConfirm() {
      //值回传给调用当前组件的父组件
      this.triggerEvent('confirm', {
        minPrice: this.data.localMinPrice,
        maxPrice: this.data.localMaxPrice
      });
      this.setData({
        dismiss: true
      });
      setTimeout(() => {
        this.setData({
          showModal: false,
          dismiss: false
        });
      }, 300);
    }
  }
});
